<template>
  <el-dialog :title="`${form.constructionId ? '修改' : '添加'}施工/承建单位`" :visible.sync="show" append-to-body :close-on-click-modal="false" :show-close="!btnLoading" width="800px" @closed="$refs.form.resetFields()">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item prop="constructionId" class="hide" />
      <el-row>
        <el-col :span="12">
          <el-form-item label="社会信用代码" prop="constructionCode"><el-input v-model.trim="form.constructionCode" placeholder="请输入社会信用代码" :maxlength="50" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司名称" prop="constructionName"><el-input v-model.trim="form.constructionName" placeholder="请输入公司名称" :maxlength="50" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司地址" prop="address"><el-input v-model.trim="form.address" placeholder="请输入公司地址" :maxlength="300" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司电话" prop="constructionTel"><el-input v-model.trim="form.constructionTel" placeholder="请输入公司电话" :maxlength="30" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="负责人名称" prop="principalName"><el-input v-model.trim="form.principalName" placeholder="请输入负责人名称" :maxlength="50" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="负责人电话" prop="principalTel"><el-input v-model.trim="form.principalTel" placeholder="请输入负责人电话" :maxlength="30" /></el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注" prop="remark"><el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :maxlength="255" /></el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="btnSubmit">确 定</el-button>
      <el-button :disabled="btnLoading" @click="show = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
// 添加或修改施工/承建单位
import { nameRule, landlineOrCellphoneRule } from '@/utils/validate'
import { editFormMixin } from '@/utils/mixin'
import { addRdcConstruction, updateRdcConstruction } from '@/api/qualityManage/cq'
export default {
  mixins: [editFormMixin],
  data() {
    return {
      primaryKey: 'constructionId',
      addApi: addRdcConstruction,
      updateApi: updateRdcConstruction,
      form: {
        constructionId: '',
        constructionCode: '',
        constructionName: '',
        address: '',
        constructionTel: '',
        principalName: '',
        principalTel: '',
        remark: ''
      },
      rules: {
        constructionCode: [{ required: true, message: '请输入社会信用代码' }, nameRule],
        constructionName: [{ required: true, message: '请输入公司名称' }, nameRule],
        address: [nameRule],
        constructionTel: [landlineOrCellphoneRule],
        principalName: [nameRule],
        principalTel: [landlineOrCellphoneRule]
      }
    }
  }
}
</script>
